package top.aicey.ai.sparring.configuration;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.redisson.config.SingleServerConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RedisConfiguration {


    @Autowired
    private RedisProperties redisProperties;

    @Bean
    public RedissonClient redissonClient() {
        Config config = new Config();
        SingleServerConfig serverConfig = config.useSingleServer();
        // 设置 Redis 服务器地址
        serverConfig.setAddress("redis://" + redisProperties.getHost()+ ":" + redisProperties.getPort());
        // 可选，设置 Redis 密码
        serverConfig.setPassword(redisProperties.getPassword());
        return Redisson.create(config);
    }
}
